package com.ljh.SimpleTradingSystem.mybatis.mapper;

import com.ljh.SimpleTradingSystem.mybatis.entity.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MessageMapper {
    @Select("select * from message where (senderId = #{senderId} and receiverId = #{receiverId})" +
            "or (senderId = #{receiverId} and receiverId = #{senderId}) order by time")
    List<Message> selectBySenderIdAndReceiverId(int senderId, int receiverId);

    @Select("select * from message where senderId = #{userId} or receiverId = #{userId}")
    List<Message> selectById(int userId);

    @Insert("insert into message(senderId, receiverId, text, time)" +
            "values (#{senderId}, #{receiverId}, #{text}, #{time})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Message message);
}
